#include "app_main_can.h"
#include "bsp_can.h"
#include "bsp_gpio.h"
#include <stdbool.h>
#include <string.h>
#include "main.h"

APP_main_can_t app_main_can;  

static void TxMainMes01(void)
{
	app_main_can.mainTxMes1.mes.life++;

    dv_CAN.fwrite_data(EM_CAN_2,TX_MES1_ID, app_main_can.mainTxMes1.data, 8);
}

static void TXMain(void)
{
	static uint16_t tick = 0;
	tick++;	
	if(tick<SYS_HEART_MS(100))
	{
		return;
	}
	else
	{
		tick = 0;	
	}
	TxMainMes01();
}


void app_main_can_rx_run(void)
{
	if(dv_CAN.main_receive_mes1_flag == SET)
	{
		dv_CAN.main_receive_mes1_flag = RESET;
		memcpy(app_main_can.mainRxMes1.data,dv_CAN.main_receive_mes1_message.rx_data,64);
		
		app_main_can.ctrl_type = app_main_can.mainRxMes1.mes.ctrl_type;
		if(app_main_can.ctrl_type == EM_CTRL_TYPE_IO)
		{
			app_main_can.io_chl    = app_main_can.mainRxMes1.mes.io_ch;
			app_main_can.io_st     = app_main_can.mainRxMes1.mes.ic_st;
		}			
	}
}

void app_main_can_tx_run(void)
{    
    TXMain();
}
